package at.guigu.web;

import at.guigu.pojo.Brand;
import at.guigu.service.BrandService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/selectByIdServlet")
public class SelectByIdServlet extends HttpServlet {
    //1 创建一个私有的BrandService对象
    private BrandService brandService = new BrandService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //2 接收id
        String id = request.getParameter("id");
        //3 调用对应的Service查询
        Brand brand = brandService.selectById(Integer.parseInt(id));
        //4 将该Brand对象存储到request域中
        request.setAttribute("brand", brand);
        //5 转发到update.jsp中
        request.getRequestDispatcher("/update.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}